package cn.com.ustudy.course.core.comp.service;

import cn.com.ustudy.course.core.model.entity.Department;
import cn.com.ustudy.course.core.model.entity.User;
import cn.com.ustudy.course.core.model.enums.UserType;
import cn.melonlib.cores.jpa.model.bean.impl.PaginationList;
import cn.melonlib.graphql.annos.GraphqlMutation;
import cn.melonlib.graphql.annos.GraphqlParameter;
import cn.melonlib.graphql.annos.GraphqlQuery;
import cn.melonlib.graphql.annos.GraphqlSchema;
import cn.melonlib.graphql.enums.GraphqlSchemaPrefixMode;
import cn.melonlib.graphql.model.enums.GraphqlQueryMode;
import org.springframework.boot.autoconfigure.graphql.ConditionalOnGraphQlSchema;
import org.springframework.stereotype.Service;

import java.util.List;

@GraphqlSchema(value = GraphqlSchemaPrefixMode.NONE)
@Service
public class UserService extends CrudService{

    @GraphqlQuery(comment = "获取用户",queryMode = GraphqlQueryMode.OFFSET)
    public PaginationList<User> users(@GraphqlParameter(value = "offset",comment = "偏移量",required = true) Long offset,
                                      @GraphqlParameter(value = "first",comment = "数据量",required = true) Integer first){
        return PaginationList.createOffset(
                List.of(
                        new User("1","李若彤",new Department("jxj","计算机",null,null),null, UserType.STUDENT,List.of("student"),null,true,1),
                        new User("2","张学友",null,null, UserType.STUDENT,List.of("student"),null,true,1),
                        new User("3","刘德华",null,null, UserType.STUDENT,List.of("student"),null,true,1),
                        new User("4","郑伊健",null,null, UserType.STUDENT,List.of("student"),null,true,1)
                ),0,4,4
        );
    }
    @GraphqlQuery(comment = "获取用户管理",queryMode = GraphqlQueryMode.OFFSET)
    public PaginationList<User> usersAdmin(@GraphqlParameter(value = "offset",comment = "偏移量",required = true) Long offset,
                                      @GraphqlParameter(value = "first",comment = "数据量",required = true) Integer first){
        return PaginationList.createOffset(
                List.of(
                        new User("1","李若彤",new Department("jxj","计算机",null,null),null, UserType.STUDENT,List.of("student"),null,true,1),
                        new User("2","张学友",null,null, UserType.STUDENT,List.of("student"),null,true,1),
                        new User("3","刘德华",null,null, UserType.STUDENT,List.of("student"),null,true,1),
                        new User("4","郑伊健",null,null, UserType.STUDENT,List.of("student"),null,true,1)
                ),0,4,4
        );
    }
    @GraphqlQuery(comment = "获取用户管理")
    public List<User> usersAll(@GraphqlParameter(value = "offset",comment = "偏移量",required = true) Long offset,
                                      @GraphqlParameter(value = "first",comment = "数据量",required = true) Integer first){
                return List.of(
                        new User("1","李若彤",new Department("jxj","计算机",null,null),null, UserType.STUDENT,List.of("student"),null,true,1),
                        new User("2","张学友",null,null, UserType.STUDENT,List.of("student"),null,true,1),
                        new User("3","刘德华",null,null, UserType.STUDENT,List.of("student"),null,true,1),
                        new User("4","郑伊健",null,null, UserType.STUDENT,List.of("student"),null,true,1)
                );
    }
    @GraphqlMutation(comment = "保存用户")
    public User saveUser(@GraphqlParameter(value = "user",comment = "用户对象",required = true) User user){
        return user;
    }

    @GraphqlQuery
    public int count(){

        return 0;
    }

}
